package rr.sb.getContent.parsers;

public class BancuriCereRoParser extends ContentParser {

    boolean step1, step2, step3, step4;

    String step1Marker = "<td width=\"80%\" class=\"dark_blue_link_2\" align=\"left\" valign=\"top\">";
    String step2Marker = "<table style=\"padding-left: 5px\" border=\"0\" width=\"100%\">";
    String step3Marker = "<tr>";
    String step4Marker = "<td class=\"dark_blue_link_2\">";
    String step5Marker = "</td>";

    String title1Marker = "<h1 class='title_css'>";
    String title2Marker = "</h1>";

    @Override
    public void processLine(String currentLine) {

	if (currentLine.contains(title1Marker)) {
	    contentTitle = currentLine.substring(currentLine.indexOf(title1Marker) + title1Marker.length(), currentLine.indexOf(title2Marker));
	    // Bancuri - Moldoveni (76 bancuri)
	    contentTitle = contentTitle.substring(contentTitle.indexOf(" - ") != -1 ? contentTitle.indexOf(" - ") + 3 : 0,
		    contentTitle.indexOf(" (") != -1 ? contentTitle.indexOf(" (") : contentTitle.length());
	}

	if (currentLine.startsWith(step1Marker)) {
	    step1 = true;
	}

	if (step1 && currentLine.startsWith(step2Marker)) {
	    step2 = true;
	}

	if (step2 && currentLine.startsWith(step3Marker)) {
	    step3 = true;
	}

	if (step3 && currentLine.startsWith(step4Marker)) {
	    step4 = true;
	    if (currentLine.endsWith(step5Marker)) {
		addContentLine(currentLine.substring(step4Marker.length(), currentLine.length() - step5Marker.length()));
		step1 = false;
		step2 = false;
		step3 = false;
		step4 = false;
		addContent();
		return;
	    } else {
		addContentLine(currentLine.substring(step4Marker.length()));
		return;
	    }
	}

	if (step4 && currentLine.endsWith(step5Marker)) {
	    addContentLine(currentLine.substring(0, currentLine.length() - step5Marker.length()));
	    step1 = false;
	    step2 = false;
	    step3 = false;
	    step4 = false;
	    addContent();
	    return;
	}

	if (step4) {
	    addContentLine(currentLine);
	    return;
	}
    }
}
